package com.sgb.member.ui.adapter;

import android.annotation.SuppressLint;
import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import androidx.databinding.library.baseAdapters.BR;

import com.sgb.member.R;
import com.sgb.member.databinding.ItemCompanyWebCollectionBinding;
import com.sgb.member.entity.CollectiveQuotationBean;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class CompanyWebCollectionAdapter extends BaseRecycleAdapter<CollectiveQuotationBean> {

    public CompanyWebCollectionAdapter(Context context, List<CollectiveQuotationBean> datas) {
        super(context, R.layout.item_company_web_collection, datas);
    }

    @SuppressLint("SetTextI18n")
    @Override
    public void convert(ItemViewHolder holder, CollectiveQuotationBean bean) {
        holder.setBinding(BR.viewModel, bean);
        ItemCompanyWebCollectionBinding binding = (ItemCompanyWebCollectionBinding) holder.getmBinding();
        if (!TextUtils.isEmpty(bean.getGroupBuyType())) {
            binding.tvCollectiveMode.setVisibility(View.VISIBLE);
            switch (bean.getGroupBuyType()) { // 汇集采购(2)或者 即报即采(1)
                case "1":
                    binding.tvCollectiveMode.setText("即报即采");
                    break;
                case "2":
                    binding.tvCollectiveMode.setText("汇集采购");
                    break;
                default:
                    binding.tvCollectiveMode.setText("");
                    break;
            }
        } else {
            binding.tvCollectiveMode.setVisibility(View.GONE);
        }

        if (!TextUtils.isEmpty(bean.getGroupbuyClass())) {
            binding.tvCollectiveType.setVisibility(View.VISIBLE);
            switch (bean.getGroupbuyClass()) { // 商品材料、机械租赁、设备租赁）
                case "1":
                    binding.tvCollectiveType.setText("商品材料");
                    break;
                case "2":
                    binding.tvCollectiveType.setText("机械租赁");
                    break;
                case "3":
                    binding.tvCollectiveType.setText("设备租赁");
                    break;
                default:
                    binding.tvCollectiveType.setText("");
                    break;
            }
        } else {
            binding.tvCollectiveType.setVisibility(View.GONE);
        }
        updateImageStatus(binding.ivBiddingStatus, bean);
    }
    private void updateImageStatus(ImageView imageView, CollectiveQuotationBean entity) {
        // 集采状态（1 集采中 2 集采结束 4 集采失败 5 加盟中 6 报价中 ）
        switch (entity.getStatus()) {
            case 1:
                switch (entity.getPriceWarning()) {//价格预警 1 大于 2 等于 3 小于
                    case 1:
                        imageView.setImageResource(R.mipmap.member_icon_jcz_dy);
                        break;
                    case 2:
                        imageView.setImageResource(R.mipmap.member_icon_jcz_dengyu);
                        break;
                    case 3:
                        imageView.setImageResource(R.mipmap.member_icon_jcz_xy);
                        break;
                    default:
                        break;
                }
                break;
            case 2:
                imageView.setImageResource(R.mipmap.member_icon_jcwc);
                break;
            case 4:
                imageView.setImageResource(R.mipmap.member_icon_jcsb);
                break;
            case 5:
                imageView.setImageResource(R.mipmap.member_icon_jmz_qt);
                break;
            case 6:
                switch (entity.getPriceWarning()) {//价格预警 1 大于 2 等于 3 小于
                    case 1:
                        imageView.setImageResource(R.mipmap.member_icon_bjz_dy);
                        break;
                    case 2:
                        imageView.setImageResource(R.mipmap.member_icon_bjz_dengyu);
                        break;
                    case 3:
                        imageView.setImageResource(R.mipmap.member_icon_bjz_xy);
                        break;
                    default:
                        imageView.setImageResource(R.mipmap.member_icon_bjz_dengyu);
                        break;
                }
//                imageView.setImageResource(R.drawable.icon_bjz);
                break;
            default:
                imageView.setImageResource(R.mipmap.member_icon_jcz);
                break;
        }
    }


}
